#include "testview.h"

#include <QGLBuilder>
#include <QGLCube>
#include <QGLTexture2D>
#include <QGLMaterial>
#include <QDebug>

TestView::TestView(QWindow *parent)
    : QGLView(parent)
    , cube(0)
    , texture(0)
{
    QGLBuilder builder;
    builder << QGL::Faceted << QGLCube(2.5f);
    cube = builder.finalizedSceneNode();

    QGLMaterial *mat = new QGLMaterial;
    mat->setColor(QColor(170, 202, 0));
    mat->setTextureUrl(QUrl("qrc:/images/main.jpg"));
    texture = mat->texture();
    cube->setMaterial(mat);

    cube->setEffect(QGL::LitDecalTexture2D);
}

TestView::~TestView()
{
    texture->cleanupResources();
    delete cube;
}

void TestView::initializeGL(QGLPainter * /*painter*/)
{
    glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
}

void TestView::paintGL(QGLPainter *painter)
{
    painter->modelViewMatrix().rotate(45.0f, 1.0f, 1.0f, 1.0f);
    cube->draw(painter);
}
